|
|
|
|
|
|
|
Instead of writing two separate proceduresone to load the combo box and one to load the list boxyou can write one generic routine that loads either control. Heres the code written in each of the Click events of the command buttons on the sample form: |
|
|
|
 |
|
|
|
|
Private Sub cmdCombo_Click ()
Call StateLoad(cboStates)
End Sub
Private Sub cmdList_Click ()
Call StateLoad(lstStates)
End Sub |
|
|
|
|
|
|
|
|
The routine to load either the combo box or list box is very simple for this illustration. The StateLoad() procedure accepts any type of control as the name ctlStates. The ctlStates argument is then used to add items to the list with some hard-coded values: |
|
|
|
 |
|
|
|
|
Public Sub StateLoad(ctlStates As Control)
With ctlStates
.Clear
.AddItem "Iowa"
.AddItem "California"
.AddItem "Arizona"
.AddItem "Nevada"
.AddItem "Arkansas"
.AddItem "Washington"
.AddItem "Texas"
.AddItem "Nebraska"
.AddItem "Utah"
.AddItem "Kentucky"
End With
End Sub |
|
|
|
|
|
|
|
|
Although, literally, any type of control could be passed to this procedure, the only controls that would work are list boxes and combo boxes or any type of control that has an AddItem method. If a text box was passed to this routine, it would bomb as soon as the Clear method was invoked. Therefore it is a good idea to check the type of object in the procedure before using that object. |
|
|
|
|
|